export default [
    {
        url:'/asset/getAssetsInfo',
        method:'post',
        response:(data)=>{
            const result = {
                "flag":true,
                "code":200,
                "msg":"操作成功",
                "data":{
                    "page":{
                        "pageSize":10,
                        "currentPage":1,
                        "total":1,
                    },
                    "assetList":[
                        {
                            "ip":"192.168.1.1",
                            "os":"",
                            "asset_type":"路由器",
                            "id":"165743",
                            "web_infos":[
                                {
                                    "uri": "192.168.1.1",
                                    "code":200,
                                    "title":"TL-WDR6500",
                                    "protocol":"http",
                                    "port":80,
                                    "value":0
                                }
                            ],
                            "firewall_policies":[],
                            "name":"路由器",
                            "vulnerabilities":[],
                            "services":[]
                        },
                        {
                            "ip":"192.168.1.71",
                            "os":"Linux Kernel 5.4.0-113-generic on Ubuntu 20.04",
                            "asset_type":"服务器",
                            "id":"168945",
                            "web_infos":[
                                {
                                    "uri": "192.168.1.71:8834",
                                    "code":400,
                                    "title":"400 Bad Request",
                                    "protocol":"http",
                                    "port":8834,
                                    "value":0
                                },
                                {
                                    "uri": "192.168.1.71:8834",
                                    "code":200,
                                    "title":"Nessus",
                                    "protocol":"https",
                                    "port":8834,
                                    "value":0
                                },
                                {
                                    "uri": "192.168.1.71",
                                    "code":200,
                                    "title":"Vite App",
                                    "protocol":"http",
                                    "port":80,
                                    "value":0
                                },
                                {
                                    "uri": "192.168.1.71:8081",
                                    "code":200,
                                    "title":"VECTR Dashboard",
                                    "protocol":"https",
                                    "port":8081,
                                    "value":0
                                },
                            ],
                            "firewall_policies":[],
                            "name":"服务器",
                            "vulnerabilities":[
                                {
                                    "cve_id":"CVE-2019-5527",
                                    "risk_level":"HIGH",
                                },
                                {
                                    "cve_id":"CVE-2021-35550",
                                    "risk_level":"MEDIUM",
                                },
                            ],
                            "services":[
                                {
                                    "name":"redis",
                                    "version":"",
                                    "value":0,
                                    "vendor":"",
                                    "description":"",
                                    "port":6379
                                }
                            ]
                        },
                        {
                            "ip":"192.168.1.108",
                            "os":"Microsoft Windows 7 Ultimate",
                            "asset_type":"主机",
                            "id":"169643",
                            "web_infos":[],
                            "firewall_policies":[],
                            "name":"LENOVO-PC",
                            "vulnerabilities":[
                                {
                                    "cve_id":"CVE-2019-0708",
                                    "risk_level":"CRITICAL",
                                },
                                {
                                    "cve_id":"CVE-2012-0002",
                                    "risk_level":"HIGH"
                                },
                                {
                                    "cve_id":"CVE-2014-6321",
                                    "risk_level":"HIGH"
                                },
                                {
                                    "cve_id":"CVE-2017-0143",
                                    "risk_level":"HIGH"
                                },
                                {
                                    "cve_id":"CVE-2016-0128",
                                    "risk_level":"MEDIUM"
                                },
                                {
                                    "cve_id":"CVE-2005-1794",
                                    "risk_level":"MEDIUM"
                                },
                            ],
                            "services":[]
                        }
                    ]
                }
            }
            let assetList;
            if (data.query.ip!=null&&data.query.ip!='') {
                assetList = result.data.assetList.filter(item => {return item.ip === data.query.ip})
                result.data.assetList = assetList;
            }
            return result
        }
    },
    {
        url: '/asset/getAssetInfo',
        method: 'post',
        response:(data)=>{
            const assetList = [
                {
                    "ip":"192.168.1.1",
                    "os":"",
                    "asset_type":"路由器",
                    "id":"165743",
                    "web_infos":[
                        {
                            "uri": "192.168.1.1",
                            "code":200,
                            "title":"TL-WDR6500",
                            "protocol":"http",
                            "port":80,
                            "value":0
                        }
                    ],
                    "firewall_policies":[],
                    "name":"路由器",
                    "vulnerabilities":[],
                    "services":[]
                },
                {
                    "ip":"192.168.1.71",
                    "os":"Linux Kernel 5.4.0-113-generic on Ubuntu 20.04",
                    "asset_type":"服务器",
                    "id":"168945",
                    "web_infos":[
                        {
                            "uri": "192.168.1.71:8834",
                            "code":400,
                            "title":"400 Bad Request",
                            "protocol":"http",
                            "port":8834,
                            "value":0
                        },
                        {
                            "uri": "192.168.1.71:8834",
                            "code":200,
                            "title":"Nessus",
                            "protocol":"https",
                            "port":8834,
                            "value":0
                        },
                        {
                            "uri": "192.168.1.71",
                            "code":200,
                            "title":"Vite App",
                            "protocol":"http",
                            "port":80,
                            "value":0
                        },
                        {
                            "uri": "192.168.1.71:8081",
                            "code":200,
                            "title":"VECTR Dashboard",
                            "protocol":"https",
                            "port":8081,
                            "value":0
                        },
                    ],
                    "firewall_policies":[],
                    "name":"服务器",
                    "vulnerabilities":[
                        {
                            "cve_id":"CVE-2019-5527",
                            "risk_level":"HIGH",
                        },
                        {
                            "cve_id":"CVE-2021-35550",
                            "risk_level":"MEDIUM",
                        },
                    ],
                    "services":[
                        {
                            "name":"redis",
                            "version":"",
                            "value":0,
                            "vendor":"",
                            "description":"",
                            "port":6379
                        }
                    ]
                },
                {
                    "ip":"192.168.1.108",
                    "os":"Microsoft Windows 7 Ultimate",
                    "asset_type":"主机",
                    "id":"169643",
                    "web_infos":[],
                    "firewall_policies":[],
                    "name":"LENOVO-PC",
                    "vulnerabilities":[
                        {
                            "cve_id":"CVE-2019-0708",
                            "risk_level":"CRITICAL",
                        },
                        {
                            "cve_id":"CVE-2012-0002",
                            "risk_level":"HIGH"
                        },
                        {
                            "cve_id":"CVE-2014-6321",
                            "risk_level":"HIGH"
                        },
                        {
                            "cve_id":"CVE-2017-0143",
                            "risk_level":"HIGH"
                        },
                        {
                            "cve_id":"CVE-2016-0128",
                            "risk_level":"MEDIUM"
                        },
                        {
                            "cve_id":"CVE-2005-1794",
                            "risk_level":"MEDIUM"
                        },
                    ],
                    "services":[]
                }
            ]
            const result = {
                "flag":true,
                "code":200,
                "msg":"操作成功！"
            }
            const asset = assetList.find((item)=>item.id===data.query.id)
            Object.assign(result,{'data':asset})
            return result
        }
    },
    {
        url:'/asset/getVulnerabilities',
        method: 'post',
        response:(data)=>{
            // console.log(data.query)
            const result={
                "flag":true,
                "code":200,
                "msg":"操作成功",
                "data":{
                    "page":{
                        "pageSize":10,
                        "currentPage":1,
                        "total":1,
                    },
                    "vulnerabilityList":[
                        {
                            "cve_id":"CVE-2019-5527",
                            "risk_level":"HIGH",
                            "cvss_v3":8.8,
                            "cvss_v2":7.2,
                            "affected":["192.168.1.71"]
                        },
                        {
                            "cve_id":"CVE-2021-35550",
                            "risk_level":"MEDIUM",
                            "cvss_v3":5.9,
                            "cvss_v2":7.1,
                            "affected":["192.168.1.71"]
                        },
                        {
                            "cve_id":"CVE-2019-0708",
                            "risk_level":"CRITICAL",
                            "cvss_v3":9.8,
                            "cvss_v2":10,
                            "affected":["192.168.1.108"]
                        },
                        {
                            "cve_id":"CVE-2012-0002",
                            "risk_level":"HIGH",
                            "cvss_v3":Number.NaN,
                            "cvss_v2":9.3,
                            "affected":["192.168.1.108"]
                        },
                        {
                            "cve_id":"CVE-2014-6321",
                            "risk_level":"HIGH",
                            "cvss_v3":Number.NaN,
                            "cvss_v2":10,
                            "affected":["192.168.1.108"]
                        },
                        {
                            "cve_id":"CVE-2017-0143",
                            "risk_level":"HIGH",
                            "cvss_v3":8.1,
                            "cvss_v2":9.3,
                            "affected":["192.168.1.108"]
                        },
                        {
                            "cve_id":"CVE-2016-0128",
                            "risk_level":"MEDIUM",
                            "cvss_v3":6.8,
                            "cvss_v2":5.8,
                            "affected":["192.168.1.108"]
                        },
                        {
                            "cve_id":"CVE-2005-1794",
                            "risk_level":"MEDIUM",
                            "cvss_v3":Number.NaN,
                            "cvss_v2":6.4,
                            "affected":["192.168.1.108"]
                        },
                    ]
                }
            }
            let vulnerabilityList;
            if (data.query.cve_id!=null&&data.query.cve_id!='') {
                vulnerabilityList = result.data.vulnerabilityList.filter(
                    item => item.cve_id === data.query.cve_id)
                result.data.vulnerabilityList = vulnerabilityList;
            }
            if (data.query.risk_level!=null&&data.query.risk_level!='') {
                vulnerabilityList = result.data.vulnerabilityList.filter(
                    item => data.query.risk_level.includes(item.risk_level))
                result.data.vulnerabilityList = vulnerabilityList;
            }
            if (data.query.sort!=null&&data.query.sort!=''){
                if (data.query.order==='desc') {
                    if (data.query.sort==='cve_id')
                        result.data.vulnerabilityList.sort((x,y)=>{
                            if (x>y)
                                return -1;
                            else if (x===y)
                                return 0;
                            else
                                return 1;
                        })
                    else if (data.query.sort=='cvss_v2')
                        result.data.vulnerabilityList.sort((x,y)=>y.cvss_v2-x.cvss_v2);
                    else
                        result.data.vulnerabilityList.sort((x,y)=>y.cvss_v3-x.cvss_v3);
                }else {
                    if (data.query.sort==='cve_id')
                        result.data.vulnerabilityList.sort((x,y)=>{
                            if (x>y)
                                return 1;
                            else if (x===y)
                                return 0;
                            else
                                return -1;
                        })
                    else if (data.query.sort=='cvss_v2')
                        result.data.vulnerabilityList.sort((x,y)=>x.cvss_v2-y.cvss_v2);
                    else
                        result.data.vulnerabilityList.sort((x,y)=>x.cvss_v3-y.cvss_v3);
                }
            }
            return result;
        }
    },
    {
        url: '/asset/getServices',
        method: 'post',
        response:(data)=>{
            const result={
                "flag":true,
                "code":200,
                "msg":"操作成功",
                "data": {
                    "page": {
                        "pageSize": 10,
                        "currentPage": 1,
                        "total": 1,
                    },
                    serviceList:[
                        {
                            'id':'191264',
                            'name':'redis',
                            'port':6379,
                            'deploy':["192.168.1.71"],
                            'deployNum':1
                        }
                    ]
                }
            }
            let serviceList;
            if (data.query.name!=null&&data.query.name!='') {
                serviceList = result.data.serviceList.filter(
                    item => item.name === data.query.name)
                result.data.serviceList = serviceList;
            }
            if (data.query.port!=null&&data.query.port!='') {
                serviceList = result.data.serviceList.filter(
                    item => item.port === data.query.port)
                result.data.serviceList = serviceList;
            }
            if (data.query.sort!=null&&data.query.sort!=''){
                if (data.query.order==='desc') {
                    result.data.serviceList.sort((x,y)=>y.deployNum-x.deployNum);
                }else {
                    result.data.serviceList.sort((x,y)=>x.deployNum-y.deployNum);
                }
            }
            return result
        }
    }
]